﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 角度计算器
{
    public partial class 角度计算器 : Form
    {
        public 角度计算器()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            double AB = 0;
            double AC = 0;
            double BC = 0;
            try
            {
                Location a = new Location(double.Parse(textA_X.Text), double.Parse(textA_Y.Text));
                Location b = new Location(double.Parse(textB_X.Text), double.Parse(textB_Y.Text));
                Location c = new Location(double.Parse(textC_X.Text), double.Parse(textC_Y.Text));
                AB = length(a, b);
                AC = length(a, c);
                BC = length(b, c);
            }
            catch(Exception ex)
            {
                MessageBox.Show("参数填写错误，请使用正确格式！");
            }
            lblResultA.Text = count(BC, AC, AB);
            lblResultB.Text = count(AC, BC, AB);
            lblResultC.Text = count(AB, AC, BC);
        }

        private string count(double lenMain,double len1,double len2)
        {
            double cos = 0;

            cos = ((len1 * len1)+(len2 * len2)-(lenMain * lenMain))/(2*len2*len1);
            cos = Math.Acos(cos)*180/Math.PI;
            cos = Math.Round(cos, 2);

            string result = cos + "度";
            return result;
        }

        private double length(Location lc1,Location lc2)
        {
            double x = lc1.X - lc2.X;
            double y = lc1.Y - lc2.Y;
            double result = Math.Sqrt(x * x + y * y);
            return result;
        }
    }
}
